package Action.Manager;

import Bean.Log.SystemLogEntity;
import com.opensymphony.xwork2.ActionSupport;
import org.hibernate.Session;
import tools.HibernateTools;

import java.util.List;

public class BookAltLog extends ActionSupport {
    private String key;//查找关键字
    List<SystemLogEntity> data;

    private String showAll(){
        Session session= HibernateTools.getSession();
        data=session.createQuery("from SystemLogEntity where remark=? order by id desc ").setParameter(0,SystemLogEntity.remark_book).setMaxResults(100)
                .getResultList();
        return SUCCESS;
    }
    public String find_log(){
        if (key==null||key.equals("")){
            return showAll();
        }
        Session session= HibernateTools.getSession();
        data=session.createQuery("from SystemLogEntity where remark=? and (cast(bookId as string ) like ?) order by id desc ")
                .setParameter(0,SystemLogEntity.remark_book)
                .setParameter(1,"%"+key+"%")
                .setMaxResults(100)
                .getResultList();
        return SUCCESS;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public List<SystemLogEntity> getData() {
        return data;
    }

    public void setData(List<SystemLogEntity> data) {
        this.data = data;
    }
}
